<template>
  <a-modal
    title="审批"
    :visible="visible"
    ok-text="确定"
    @ok="handleSubmit"
    @cancel="handleCancel"
    :destroyOnClose="true"
  >
    <a-form-model ref="form" :model="queryParam" :rules="validatorRules">
      <a-form-model-item label="申批结果" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="flag">
        <a-select
          show-search
          placeholder="请选择"
          option-filter-prop="children"
          title="请选择申批结果"
          v-model="queryParam.flag"
        >
          <a-select-option v-for="(item, index) in approvalList" :key="index" :value="item.value">
            {{ item.label }}
          </a-select-option>
        </a-select>
      </a-form-model-item>
      <a-form-model-item label="说明" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="opinion">
        <a-textarea
          :auto-size="{ minRows: 5, maxRows: 10 }"
          placeholder="请输入说明"
          v-model="queryParam.opinion"
        ></a-textarea>
      </a-form-model-item>
    </a-form-model>
  </a-modal>
</template>

<script>
import moment from 'moment'
import { httpAction, getAction, postAction, deleteAction } from '@/api/manage'
import NKUpload from '../../../components/NKUpload'
export default {
  name: 'UserModal',
  components: { NKUpload },
  data() {
    return {
      queryParam: {},
      yearPickShow: false,
      visible: false,
      validatorRules: {
        flag: [{ required: true, message: '请选择审批结果' }],
        opinion: [{ required: true, message: '请输入说明' }],
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      approvalList: [
        {
          label: '上报',
          value: 1,
        },
        {
          label: '通过并上报',
          value: 2,
        },
        {
          label: '通过',
          value: 3,
        },
        {
          label: '驳回',
          value: 4,
        },
      ],
      rowData: {},
      url: {
        getApprover: '/sys/user/queryAuditInfoByOrgCode',
        add: '/check/assessment/chooseCheck',
      },
    }
  },
  created() {},
  methods: {
    handleSubmit() {
      let params = {
        ...this.queryParam,
        id: this.rowData.id,
      }
      this.$refs.form.validate((valid) => {
        if (valid) {
          postAction(this.url.add, params).then((res) => {
            if (res.success) {
              this.$message.success(res.message)
              this.visible = false
              this.queryParam = {}
              this.$emit('submited')
            } else {
              this.$message.error(res.message)
            }
          })
        }
      })
    },
    handleCancel(e) {
      this.queryParam = {
        year: '',
      }
      this.visible = false
    },
    moment,
    // 得到年份选择器的值
    handlePanelChange(value) {
      this.queryParam.year = moment(value).format('YYYY')
      this.yearPickShow = false
      this.$refs.form.validateField('year', (error) => {
        console.log(error)
      })
    },
    // 弹出日历和关闭日历的回调
    handleOpenChange(status) {
      this.yearPickShow = status
    },
  },
}
</script>

<style scoped>
</style>
